import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import path from "path";
import { federation } from "@module-federation/vite";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    federation({
      name: "host",
      remotes: {
        online_exam_pc: {
          type: "module",
          name: "online_exam_pc",
          entry: "http://localhost:5173/remoteEntry.js",
          entryGlobalName: "online_exam_pc",
          shareScope: "default",
        },
        template: {
          type: "amd",
          name: "template",
          entry: "http://10.80.101.57:8080/remoteEntry.js",
          entryGlobalName: "template",
          shareScope: "default",
        },
      },
      filename: "remoteEntry.js",
    }),
  ],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  },

  server: {
    port: 5003,
    origin: "http://localhost:5003",
    proxy: {
      "/test-post": {
        target: "http://127.0.0.1:3000/",
        changeOrigin: true,
        // ws: true,
        rewrite: (pathStr) => {
          console.log(pathStr, "asd");
          return pathStr;
        },
      },
      "/test-get": {
        target: "http://127.0.0.1:3000/",
        changeOrigin: true,
        rewrite: (path) => {
          // path.replace(/\/test/, '')
          return path;
        },
      },
      "/node-api": {
        target: "http://127.0.0.1:3000/",
        changeOrigin: true,
        rewrite(path) {
          path = path.replace(/\/node-api\//, "/");
          console.log(path);
          return path;
        },
      },
    },
  },
  css: {
    preprocessorOptions: {
      // 引入全局 scss
      scss: {
        additionalData: `@import "./src/style/global.scss";`,
      },
    },
  },
});
